﻿using System.Collections.Generic;
using System.Windows.Input;
using Bulb.Core.Services.CollectionService;
using Bulb.Core.Services.CollectionService.Messages;
using Cirrious.MvvmCross.Plugins.JsonLocalisation;
using Cirrious.MvvmCross.Plugins.Messenger;
using Cirrious.MvvmCross.ViewModels;

namespace Bulb.Core.ViewModels
{
    public class SettingsViewModel : BaseViewModel
    {
        private readonly IMvxTextProviderBuilder _builder;
        private readonly IMvxMessenger _messenger;

        private string _language;
        public string Language
        {
            get { return _language; }
            set
            {
                _language = value;
                RaisePropertyChanged(() => Language);

                _builder.LoadResources(_language);
                RaisePropertyChanged(() => TextSource);

                _messenger.Publish(new LanguageChangedMessage(this));
            }
        }

        private List<string> _languageList;
        public List<string> LanguageList
        {
            get { return _languageList; }
            set { _languageList = value; RaisePropertyChanged(() => LanguageList); }
        }  

        public SettingsViewModel(ICollectionService collectionService, IMvxTextProviderBuilder builder, IMvxMessenger messenger)
            : base(collectionService)
        {
            _builder = builder;
            _messenger = messenger;
            
            _languageList = new List<string> { "Dutch", "English" };
            Language = _languageList[1];
        }
        
        private MvxCommand _addCommand;
        public ICommand AddCommand
        {
            get
            {
                return _addCommand = _addCommand ?? new MvxCommand(() => ShowViewModel<AddBulbViewModel>());
            }
        }
    }
}